#include <asm-arm/irq.h>
#include <asm-arm/bitops.h>
#include <goldfish/types.h>
#ifndef HEAD_H
#define HEAD_H

#define IORESOURCE_TYPE_BITS	0x00000f00	/* Resource type */
#define IORESOURCE_IO		0x00000100
#define IORESOURCE_MEM		0x00000200
#define IORESOURCE_IRQ		0x00000400
	
/*
 * Architecture ioremap implementation.
 */
#define MT_DEVICE		0
#define MT_DEVICE_NONSHARED	1
#define MT_DEVICE_CACHED	2
#define MT_DEVICE_WC		3

typedef u32 resource_size_t;
/*
 * Resources are tree-like, allowing
 * nesting etc..
 */
struct resource {
	resource_size_t start;
	resource_size_t end;
	const char *name;
	unsigned long flags;
	struct resource *parent, *sibling, *child;
};

struct platform_device {
	const char	* name;
	int		id;
	//modify struct device	dev;
	u32		num_resources;
	struct resource	* resource;
};

struct machine_desc {
	/*
	 * Note! The first four elements are used
	 * by assembler code in head.S, head-common.S
	 */
	unsigned int		nr;		/* architecture number	*/
	unsigned int		phys_io;	/* start of physical io	*/
	unsigned int		io_pg_offst;	/* byte offset for io 
						 * page tabe entry	*/

	const char		*name;		/* architecture name	*/
	unsigned long		boot_params;	/* tagged list		*/

	unsigned int		video_start;	/* start of video RAM	*/
	unsigned int		video_end;	/* end of video RAM	*/

	unsigned int		reserve_lp0 :1;	/* never has lp0	*/
	unsigned int		reserve_lp1 :1;	/* never has lp1	*/
	unsigned int		reserve_lp2 :1;	/* never has lp2	*/
	unsigned int		soft_reboot :1;	/* soft reboot		*/
	//modify void			(*fixup)(struct machine_desc *,
	//modify 				 struct tag *, char **,
	//modify 				 struct meminfo *);
	void			(*map_io)(void);/* IO mapping function	*/
	void			(*init_irq)(void);
	//modify struct sys_timer	*timer;		/* system tick timer	*/
	void 			(*timer_init)(void);
	void			(*init_machine)(void);
};

/*#ifndef IRQ_NONE
//modify typedef void irqreturn_t;
#define IRQ_NONE
#define IRQ_HANDLED
#define IRQ_RETVAL(x)
#endif*/


#define IRQF_DISABLED		0x00000020
#define IRQF_SAMPLE_RANDOM	0x00000040
#define IRQF_SHARED		0x00000080
#define IRQF_PROBE_SHARED	0x00000100
#define IRQF_TIMER		0x00000200
#define IRQF_PERCPU		0x00000400
#define IRQF_NOBALANCING	0x00000800
#define IRQF_IRQPOLL		0x00001000
	
typedef struct pm_message {
	int event;
} pm_message_t;

#define CONSBUFSIZE 512

struct console{
        uint8_t buf[CONSBUFSIZE];
        uint32_t rpos;
        uint32_t wpos;
};

extern struct console cons;

struct platform_driver {
	int (*probe)(struct platform_device *);
	int (*remove)(struct platform_device *);
	void (*shutdown)(struct platform_device *);
	int (*suspend)(struct platform_device *, pm_message_t state);
	int (*suspend_late)(struct platform_device *, pm_message_t state);
	int (*resume_early)(struct platform_device *);
	int (*resume)(struct platform_device *);
	//modify struct device_driver driver;
};	
static inline unsigned long resource_type(struct resource *res)
{
	return res->flags & IORESOURCE_TYPE_BITS;
}

struct resource *platform_get_resource(struct platform_device *dev,unsigned int type, unsigned int num);

	


struct work_struct;
typedef void (*work_func_t)(struct work_struct *work);
struct work_struct {
	struct {
	volatile int counter;
	} data;
#define WORK_STRUCT_PENDING 0		/* T if work item pending execution */
#define WORK_STRUCT_FLAG_MASK (3UL)
#define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)
	struct list_head entry;
	work_func_t func;
#ifdef CONFIG_LOCKDEP
	struct lockdep_map lockdep_map;
#endif
};

static inline int is_event_supported(unsigned int code,
				     unsigned long *bm, unsigned int max)
{
	return code <= max && test_bit(code, bm);
}

extern void *__arm_ioremap(unsigned long phys_addr, size_t size, unsigned int mtype);
#define ioremap(cookie,size)        __arm_ioremap(cookie, size, MT_DEVICE)

int request_irq(unsigned int irq, action_handler handler,unsigned long irqflags, const char *devname, void *dev_id);

int platform_get_irq(struct platform_device *dev, unsigned int num);

extern struct platform_device goldfish_pdev_bus_device;
extern struct machine_desc machdesc;
extern struct platform_driver goldfish_pdev_bus_driver;
extern struct platform_driver events_driver;
extern struct platform_driver goldfish_fb_driver;
extern struct platform_driver goldfish_audio_driver;
extern struct platform_driver goldfish_mmc_driver;
extern struct mmc_host *mmc;
extern struct platform_driver goldfish_battery_device;
extern struct platform_driver goldfish_nand_driver;
extern struct goldfish_nand *nand;
//rtc
extern struct platform_driver goldfish_timer;
int goldfish_rtc_read_time(/*struct device *dev, */struct rtc_time *tm);

#endif
